package com.project.frame.common.controller;

import com.project.frame.common.cache.sys.OnLineUserCache;
import com.project.frame.common.utils.convert.DateConvertEditor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Validator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * desc
 *
 * @author lw007
 * @date 2021/12/23
 */
@Slf4j
public class BaseController {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    protected HttpServletResponse response;

    @InitBinder
    protected void initBinder(WebDataBinder binder) throws Exception{
        binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
        binder.registerCustomEditor(Date.class, new DateConvertEditor());
//        binder.setValidator(this.getValidator());
    }

    /**
     * @return
     */
    protected Validator getValidator() {
        return null;
    }

    public Long getUserId(){
        return OnLineUserCache.getInstance().getUserId();
    }

    public String getUserName(){
        return OnLineUserCache.getInstance().getCurrentUser().getName();
    }

}
